package me.keiwu.admin.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import me.keiwu.admin.rpc.UserRpc;
import me.keiwu.admin.service.UserLabelService;
import me.keiwu.pub.data.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 用户管理
 */
@RequestMapping("/api/myuser")
@Controller
public class MyUserController {

    private static final Logger logger = LoggerFactory.getLogger(MyUserController.class);

    @Autowired
    private UserLabelService userLabelService;
    @Autowired
    UserRpc userRpc;

    //单个更新
    @ResponseBody
    @RequestMapping(value = "/updateGold")
    public Response update(Long userId, int newGold){
        logger.info("updateGold userId={}, newGold={}", userId, newGold);
        userRpc.updateGold(userId, newGold);
        return Response.ok();
    }


    @ResponseBody
    @RequestMapping(value = "/detail")
    public Response detail(Long userId){
        JSONObject obj = JSONObject.parseObject(userRpc.userInfo(userId));
        obj.put("userLabelPage", userLabelService.findAllUserLabel(userId));
        return Response.ok(obj);
    }


    @ResponseBody
    @RequestMapping(value = "/daily")
    public Response daily(String nickName, Integer page, Integer size){
        JSONObject obj = JSON.parseObject(userRpc.dailyLoginUser(nickName, page, size));
        return Response.ok(obj);
    }


    @ResponseBody
    @RequestMapping(value = "/history")
    public Response history(String nickName, Integer page, Integer size){
        JSONObject obj = JSON.parseObject(userRpc.historyLoginUser(nickName, page, size));
        return Response.ok(obj);
    }

}
